import Storage from '@/plugins/store'
import {
  getAllConfig
} from '@/api/resource/config'
export default {
  state: {
    app_name: 'Lablog',
    app_status: true,
    app_close_tip: 'Sorry, we are maintaining the website.',
    app_notification: '',
    app_title: '✨王宁凯的个人博客',
    app_keywords: '王宁凯,ningkai.wang,个人博客,lablog,技术分享',
    app_description: '王宁凯的个人技术博客',
    app_allow_comment: true,
    app_allow_message: true,
    app_allow_reward: false,
    app_reward_alipay: 'https://i.loli.net/2018/08/28/5b8508ab0140c.png',
    app_reward_wechat: 'https://i.loli.net/2018/08/28/5b8508aaf037f.png',
    app_allow_subscribe: false,
    app_admin_name: 'IMWNK',
    app_admin_avatar: 'https://i.loli.net/2018/10/18/5bc8511910632.jpg',
    app_admin_info: '👑 TO BE A PHP ARTISAN',
    app_admin_bio: '耐心。耐心并非技术技巧，但却能让程序员走的更远。写代码不容易，越是有耐心的程序员，越有可能获得成功。',
    app_admin_mail: '1655586865@qq.com',
    app_admin_mailto: 'https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=QC4pLicrISluNyEuJwAmLzgtISksbiMvLQ',
    app_admin_weibo: 'https://weibo.com/wangningkai0614',
    app_admin_github: 'https://git.io/imwnk',
    app_admin_qq: '',
    app_icp_num: '苏ICP备16063755号-1',
    app_110beian_num: '苏公网安备 32040402000323号',
    app_110beian_link: 'http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=32040402000323',
    app_water_mark: '',
    app_water_mark_link: ''
  },
  mutations: {
    setAppConfig (state, config) {
      for (let value in config) {
        state[value] = config[value]
      }
      Storage.set('app', config)
    },
    clearAppConfig () {
      Storage.set('app', {})
    }
  },
  actions: {
    loadAppConfig ({
      commit
    }) {
      return new Promise((resolve, reject) => {
        getAllConfig().then(res => {
          const config = res
          commit('setAppConfig', config)
          resolve(res)
        }).catch(err => {
          reject(err)
        })
      })
    }
  }
}
